package com.dawn.module.cms.dal.mysql.category;

import java.util.*;

import com.dawn.framework.common.pojo.PageResult;
import com.dawn.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.dawn.framework.mybatis.core.mapper.BaseMapperX;
import com.dawn.module.cms.controller.app.category.vo.AppCategoryListReqVO;
import com.dawn.module.cms.dal.dataobject.category.CategoryDO;
import org.apache.ibatis.annotations.Mapper;
import com.dawn.module.cms.controller.admin.category.vo.*;

/**
 * 类别管理 Mapper
 *
 * @author mamba 4 left
 */
@Mapper
public interface CmsCategoryMapper extends BaseMapperX<CategoryDO> {

    default PageResult<CategoryDO> selectPage(CategoryPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CategoryDO>()
                .eqIfPresent(CategoryDO::getParentId, reqVO.getParentId())
                .eqIfPresent(CategoryDO::getProperty, reqVO.getProperty())
                .eqIfPresent(CategoryDO::getType, reqVO.getType())
                .likeIfPresent(CategoryDO::getName, reqVO.getName())
                .likeIfPresent(CategoryDO::getSubName, reqVO.getSubName())
                .eqIfPresent(CategoryDO::getCategoryKey, reqVO.getCategoryKey())
                .eqIfPresent(CategoryDO::getModuleKey, reqVO.getModuleKey())
                .eqIfPresent(CategoryDO::getDescription, reqVO.getDescription())
                .eqIfPresent(CategoryDO::getPinyin, reqVO.getPinyin())
                .eqIfPresent(CategoryDO::getBanner, reqVO.getBanner())
                .eqIfPresent(CategoryDO::getIco, reqVO.getIco())
                .eqIfPresent(CategoryDO::getKeywords, reqVO.getKeywords())
                .eqIfPresent(CategoryDO::getPath, reqVO.getPath())
                .eqIfPresent(CategoryDO::getLinkUrl, reqVO.getLinkUrl())
                .eqIfPresent(CategoryDO::getTemplate, reqVO.getTemplate())
                .eqIfPresent(CategoryDO::getContentTemplate, reqVO.getContentTemplate())
                .eqIfPresent(CategoryDO::getContentType, reqVO.getContentType())
                .eqIfPresent(CategoryDO::getSort, reqVO.getSort())
                .eqIfPresent(CategoryDO::getVisible, reqVO.getVisible())
                .eqIfPresent(CategoryDO::getIsSearch, reqVO.getIsSearch())
                .eqIfPresent(CategoryDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(CategoryDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CategoryDO::getId));
    }

    default List<CategoryDO> selectList(AppCategoryListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<CategoryDO>()
                .likeIfPresent(CategoryDO::getProperty, reqVO.getProperty())
                .eqIfPresent(CategoryDO::getType, reqVO.getType())
                .eqIfPresent(CategoryDO::getName, reqVO.getTitle())
                .eqIfPresent(CategoryDO::getVisible, reqVO.getVisible())
                .eqIfPresent(CategoryDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(CategoryDO::getCreateTime, reqVO.getCreateTime())
                .orderByAsc(CategoryDO::getSort)
        );
    }

}